﻿using System;
using System.Web;
using System.Web.UI;
using rpxnow_library.conf;

namespace rpxlogindemo.pages
{
    public partial class Login : BasePage
    {
        private static string RPX_TOKEN_URL = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/RpxToken.ashx");

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.User.Identity.IsAuthenticated)
                Response.Redirect("~/");
        }


        protected string RpxEmbedFrameSrc
        {
            get
            {
                return string.Format("{0}?token_url={1}&language_preference=en", ApplicationConfiguration.RpxFrameUrl, this.RpxTokenUrl);
            }

        }
        protected string RpxTokenUrl
        {
            get
            {
                string url = Login.RPX_TOKEN_URL;

                if (!string.IsNullOrEmpty(Request.QueryString["returnUrl"]))
                    url += string.Format("?returnUrl={0}", Request.QueryString["returnUrl"]);

                return Server.UrlEncode(url);
            }
        }
    }
}
